package com.edu.imau.ManagerRoleInformation;

import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/add2")
public class ManagerAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String id_str = request.getParameter("role_id");
        String role_code =request.getParameter("role_code");
        String role_virtual_name =request.getParameter("role_virtual_name");
        String role_name =request.getParameter("role_name");
        String role_true_name =request.getParameter("role_true_name");
        String role_password =request.getParameter("role_password");
        String role_contact =request.getParameter("role_contact");
//        int id=Integer.parseInt(id_str);
        //2 调用model
        if(id_str == null||id_str.equals("")){
            Manager manager = new Manager(-1,role_code,role_virtual_name,role_name,role_true_name,role_password,role_contact);
            dao.addManager(manager);
        }else{
            Manager manager = new Manager(Integer.parseInt(id_str),role_code,role_virtual_name,role_name,role_true_name,role_password,role_contact);
            dao.updateManger(manager);
        }
        //3 数据交给View
        response.sendRedirect("manager.jsp");
    }
}
